<?php
/**
 * Created by PhpStorm.
 * User: qufan
 * Date: 2016/12/7 0007
 * Time: 21:34
 */

namespace Common\Logic;


class UserLogic
{

    /**
     * 检测当前用户是否为管理员
     * @param null $uid
     * @return bool
     */
    public static function is_administrator($uid = null){
        $uid = is_null($uid) ? is_login() : $uid;
        $userModel = D('User');
        $user = $userModel->find($uid);
        if($user){
            return $uid && ($user['role_id'] == 1);
        }
        return false;
    }

    public static function login($username, $password){
        $userModel = D('User');
        $uid = $userModel->login($username, $password);
        return $uid;
    }

    public static function logout(){
        $userModel = D('User');
        $userModel->logout();
    }

    public static function getJurisdiction($role_id){
        $model = M('RoleJurisdiction');
        $res = $model->field('jurisdiction_id')->where("role_id=$role_id")->select();
        if(empty($res)){
            return false;
        }
        return array_column($res, 'jurisdiction_id');
    }

}